package com.briup.ch11;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/16
 * @Description:
 */
public class Test_img {
    public static void main(String[] args) throws IOException {
        /*FileInputStream fileInputStream = new FileInputStream("2.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("2_copy.jpg");
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = fileInputStream.read(buffer))!= -1) {
            fileOutputStream.write(buffer, 0, len);
        }
        fileInputStream.close();
        fileOutputStream.close();*/
        byte[] buffer = new byte[1024];
        int n=10;
        for (int i = 0; i < n; i++) {
            FileInputStream fileInputStream = new FileInputStream("2.jpg");
            FileOutputStream fileOutputStream = new FileOutputStream("2_copy"+i+".jpg");
            System.out.println("正在复制第"+i+"张图片");
            int len = 0;
            while ((len = fileInputStream.read(buffer))!= -1) {
                //打印图片名
                fileOutputStream.write(buffer, 0, len);
            }
            fileInputStream.close();
            fileOutputStream.close();
        }
        //删除复制后的图片
        for (int i = 0; i < n; i++) {
            String path = "2_copy"+i+".jpg";
            boolean success = (new java.io.File(path)).delete();
            if (success) {
                System.out.println("删除"+path+"成功");
            } else {
                System.out.println("删除"+path+"失败");
            }
        }

    }
}
